package util

import (
	"regexp"
	"strconv"
	"unicode"
)

func ToInt(data string) int {
	r, err := strconv.Atoi(data)
	if err != nil {
		return 0
	}
	return r
}

func ToInt64(data string) int64 {
	r, err := strconv.ParseInt(data, 10, 64)
	if err != nil {
		return 0
	}
	return r
}

func FromInt(data int) string {
	return strconv.Itoa(data)
}

// IsNumeric 判断字符串是否为纯数字
func IsNumeric(s string) bool {
	match, _ := regexp.MatchString("^[0-9]+$", s)
	return match
}

func IsLetter(s string) bool {
	for _, r := range s {
		if !unicode.IsLetter(r) {
			return false
		}
	}
	return true
}
